package com.aiti.lulian.mapper;



import com.aiti.lulian.workflow.ProcessDefinition;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;


import java.util.List;


public interface ProcessDefinitionMapper extends BaseMapper<ProcessDefinition> {


    default ProcessDefinition findByIdAndIsActive(String id, Boolean isActive) {
        return selectOne(
                new QueryWrapper<ProcessDefinition>()
                        .eq("id", id)
                        .eq("is_active", isActive)
        );
    }


    default List<ProcessDefinition> findByIsActive(Boolean isActive) {
        return selectList(
                new QueryWrapper<ProcessDefinition>().eq("is_active", isActive)
        );
    }


    @Select("SELECT * FROM dj_process_definition WHERE name = #{name} AND version = #{version}")
    List<ProcessDefinition> findByNameAndVersion(@Param("name") String name, @Param("version") int version);


    @Select("SELECT MAX(version) FROM dj_process_definition WHERE name = #{name}")
    Integer findMaxVersionByName(@Param("name") String name);
}